#ifndef CWEBSOCKETTOOL_H
#define CWEBSOCKETTOOL_H

#include <QWidget>
#include <QWebSocket>
#include <QWebSocketServer>

enum EM_MESSAGE_SHOW_COLOR
{
    EM_MESSAGE_SHOW_COLOR_RED,
    EM_MESSAGE_SHOW_COLOR_BLUE,
    EM_MESSAGE_SHOW_COLOR_GREEN,
};

QT_BEGIN_NAMESPACE
namespace Ui { class CWebsocketTool; }
QT_END_NAMESPACE

class CWebsocketTool : public QWidget
{
    Q_OBJECT

public:
    CWebsocketTool(QWidget *parent = nullptr);
    ~CWebsocketTool();
    void ClientOutputMessage(QString strMessage, EM_MESSAGE_SHOW_COLOR emShowColor );
    void ServerOutputMessage(QString strMessage, EM_MESSAGE_SHOW_COLOR emShowColor );

private slots:
    void on_btnClientConnect_clicked();

    void on_btnClientDisconnect_clicked();

    void on_btnClientSendMessage_clicked();

    void on_btnOpenServer_clicked();

    void on_btnCloseServer_clicked();

    void on_btnServerSend_clicked();

    void SlotClientConnected();
    void SlotClientDisconnected();
    void SlotClientConnectError(QAbstractSocket::SocketError error);
    void SlotClientReceiveMessages(QString strMessage);

    void SlotNewConnection();
    void SlotDisconnection();
    void SlotServerMessageReceived(QString strMessage);

private:
    Ui::CWebsocketTool *ui;
    QWebSocket *m_pWebSocketClient;
    QWebSocketServer *m_pWebSocketSrever;
    QWebSocket *m_pWebSocket;
    QList<QWebSocket*> m_WebSocketList;
    QMap<QString, QWebSocket*> m_WebSocketMap;
};
#endif // CWEBSOCKETTOOL_H
